package com.meilele.dao.hongdian;

import com.meilele.entity.hongdian.ThiCaseBigType;
import com.meilele.entity.hongdian.ThiCaseLable;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ThiCaseLableMapper {
    @Delete({
        "delete from thi_case_lable",
        "where lable_id = #{lableId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer lableId);

    @Insert({
        "insert into thi_case_lable (lable_id, case_lable, ",
        "big_type_id)",
        "values (#{lableId,jdbcType=INTEGER}, #{caseLable,jdbcType=VARCHAR}, ",
        "#{bigTypeId,jdbcType=INTEGER})"
    })
    int insert(ThiCaseLable record);

    int insertSelective(ThiCaseLable record);

    /**
     * 添加标签
     * @param caseLable
     */
    @Insert({"INSERT INTO thi_lable (case_id, lable_id)\n" +
            "VALUES (#{caseId},#{lableId})"
    })
    void saveCaseLable(ThiCaseLable caseLable);

    @Select({
        "select",
        "lable_id, case_lable, big_type_id",
        "from thi_case_lable",
        "where lable_id = #{lableId,jdbcType=INTEGER}"
    })
    @ResultMap("com.meilele.dao.hongdian.ThiCaseLableMapper.BaseResultMap")
    ThiCaseLable selectByPrimaryKey(Integer lableId);

    /**
     * 查询所有的标签
     * @return
     */
    @Select("select lable_id, case_lable, big_type_id from thi_case_lable")
    @ResultMap("com.meilele.dao.hongdian.ThiCaseLableMapper.BaseResultMap")
    List<ThiCaseLable> findAllCaseLable();


    int updateByPrimaryKeySelective(ThiCaseLable record);

    @Update({
        "update thi_case_lable",
        "set case_lable = #{caseLable,jdbcType=VARCHAR},",
          "big_type_id = #{bigTypeId,jdbcType=INTEGER}",
        "where lable_id = #{lableId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(ThiCaseLable record);

    /**
     * 查询出每一个大类下的单个标签
     * @return
     */
    @Results(value = {
            @Result(column = "lable_id" , property = "lableId"),
            @Result(column = "case_lable" , property = "caseLable"),
            @Result(column = "big_type_id" , property = "bigTypeId")
    })
    @Select("SELECT lable_id, case_lable,big_type_id FROM thi_case_lable")
    List<ThiCaseLable> findSingleLable();

    /**
     * 查询所有的风格标签
     * @return
     */
    @Results(value = {
            @Result(column = "big_type_id" , property = "bigTypeId"),
            @Result(column = "case_big_type" , property = "caseBigType")
    })
    @Select("SELECT big_type_id, case_big_type FROM thi_case_big_type")
    List<ThiCaseBigType> findAllStyle();

    /**
     * 第五个模块调用的风格类型的标签
     * 此时SQL条件固定
     * @return
     */
    @Results(value = {
            @Result(column = "lable_id" , property = "lableId"),
            @Result(column = "case_lable" , property = "caseLable"),
            @Result(column = "big_type_id" , property = "bigTypeId")
    })
    @Select("SELECT lable_id, case_lable, big_type_id FROM thi_case_lable WHERE big_type_id = 1")
    List<ThiCaseLable> findStyleById();


    /**
     * 根据id查询出对应的标签
     * @param id
     * @return
     */
    @Results(value = {
            @Result(column = "lable_id" , property = "lableId"),
            @Result(column = "case_lable" , property = "caseLable"),
            @Result(column = "big_type_id" , property = "bigTypeId")
    })
    @Select("SELECT lable_id, case_lable, big_type_id FROM thi_case_lable WHERE lable_id = #{lableId}")
    ThiCaseLable findLableById(int id);

    @Results(value = {
            @Result(column = "lable_id" , property = "lableId"),
            @Result(column = "case_lable" , property = "caseLable"),
            @Result(column = "big_type_id" , property = "bigTypeId")
    })
    @Select("SELECT lable_id, case_lable, big_type_id FROM thi_case_lable WHERE lable_id = #{lableId}")
    ThiCaseLable findLablesById(int lableId);

//    @Results(value = {
//            @Result(column = "lable_id" , property = "lableId"),
//            @Result(column = "case_lable" , property = "caseLable"),
//            @Result(column = "big_type_id" , property = "bigTypeId")
//    })
//    @Select("SELECT case_lable FROM thi_case_lable WHERE lable_id = #{lableId}")
//    String findCaseLableById(int lableId);

}